package gold.digger;

import gold.utils.InputUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC442 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public List<Integer> findDuplicates(int[] nums) {
            List<Integer> res = new ArrayList<>();

            for (int i = 0; i < nums.length; i++) {
                if (nums[Math.abs(nums[i]) - 1] < 0) res.add(Math.abs(nums[i]));
                nums[Math.abs(nums[i]) - 1] *= -1;
            }

            return res;
        }
    }

    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[4,3,2,7,8,2,3,1]");
        System.out.println(solution.findDuplicates(arr));
    }

    public static void main(String[] args) throws Exception {
        LC442 an = new LC442();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
